{% extends 'umessages/base_message.html' %}
{% load i18n %}
{% load compress %}

{% block container_top %}
  <h2>
    管理协作者
  </h2>
{% endblock %}

{% block sidebar %}
  <div class="sidebar">
    <div style="padding-top: 20px;">
      <form action="" id="add_collaborator_form">
        <div id="add_form_info" class="alert alert-error" style="display: none">
        </div>
        <input type="" name="username" id="id_username" style="width:250px" />
        <button type="submit" id="btn_add_collaborator" class="btn" style="float: right">
          <i class="icon-share-alt"></i>
          添加
        </button>
      </form>
    </div>
  </div>
{% endblock %}

{% block content %}
  <div class="content" style="padding-top: 20px;">
    <table class="table table-bordered" id="collaborator_tb">
      <thead>
        <tr>
          <th style="width: 340px">用户</th>
        </tr>
      </thead>
      <tbody>
        {% for o in collaborators %}
          <tr id="u_{{o.pk}}">
            <td> 
              <a href="{% url userena_profile_detail o.username %}"> {{o}} </a> 
              (<a href="###" class="danger del">移除</a>)
            </td>
          </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
{% endblock %}

{% block footer_ext %}
  {{ block.super }}
  <script type="text/javascript">
    var url_timeline_add_collaborator_ = "{% url timeline_add_collaborator_ tl.pk %}";
    var url_timeline_remove_collaborator_ = "{% url timeline_remove_collaborator_ tl.pk %}";
  </script>
  {% compress js inline %}
  <script type="text/coffeescript">
$ -> 
  $('#add_collaborator_form').submit ->
    $.post(url_timeline_add_collaborator_, 
      {username: $('#id_username').val()},
      (d)-> 
        if d.valid
          $('#add_form_info').hide()
          $('#collaborator_tb tbody').append(d.html)
          initActBtn()
        else
          $('#add_form_info').html(d.info)
          $('#add_form_info').show()
      ,
      "json")
    return false
  initActBtn = ->
    del_btns = $("#collaborator_tb .del")
    del_btns.unbind('click')
    del_btns.click ->
      if confirm('确定要移除该用户？')
        p = $(this).parent().parent();
        upk = p[0].id.split('_')[1]
        $.post(url_timeline_remove_collaborator_, 
          {upk: upk}, 
          (d) -> 
            if d.valid
              p.fadeOut('slow', -> p.remove())
            else
              alert('移除失败')
          ,
          "json")
  initActBtn()
  </script>
  {% endcompress %}
{% endblock %}
